(function(angular) {
	'report strict';
	angular.module('fs.waf').controller('cda.report.deleteController', deleteController);
	deleteController.$inject = [ '$scope', 'Constants', 'modalService', 'layoutConfig', 'validatorConfig', 'gridService', 'authService','storageService', 'reportService' ];
	function deleteController($scope, Constants, modalService, layoutConfig, validatorConfig, gridService, authService, storageService, reportService) {
		var ctrl = this, reportInfo = $scope.$stateParams.params;
		ctrl.report = {};
		ctrl.init = function() {
			ctrl.readOnly = true;
			// init report Parameter
			reportService.initReportParameter($scope, ctrl, layoutConfig);
			// init report company
			reportService.initCompany($scope, ctrl, false, layoutConfig);
			ctrl.reportParameterGridOptions.enableRowHeaderSelection = false;
			ctrl.companyGridOptions.enableRowHeaderSelection = false;
			// init report Parameter
			reportService.initDataOptions($scope, ctrl);
			authService.delete(reportInfo).then(function(response) {
				ctrl.report = response.data;
				ctrl.report.reportParms = ctrl.report.reportParms || [];
				ctrl.report.companyRpts = ctrl.report.companyRpts || [];
				ctrl.layoutConfig = layoutConfig;
			});
		};
		
		ctrl.deleteSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.report.primaryKey]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteSubmit(ctrl.report).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};
		
		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.report.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.report.list',
					'state' : 'cda.report.list',
					'params' : {}
				}]
			});
		}

		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		
	}
})(angular);